package taglib;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

@SuppressWarnings("serial")
public class DateTag extends TagSupport {

	private long longTime;
	private Date date;
	private String style;
	public int doStartTag()  {
		return (SKIP_BODY);
	}
	
	public int doEndTag()  {
		if (style == null || style.length() == 0) {
			style = "yyyy-MM-dd";
		}
		JspWriter writer = pageContext.getOut();
		SimpleDateFormat formatter = new SimpleDateFormat(style);
		String strDate = "";
		if(date!=null){
			strDate = formatter.format(date);
		}
		else if(longTime>0){
			strDate = formatter.format(new java.util.Date(longTime));
		}
		try {
			writer.print(strDate);
		} catch (Exception e) {

		}
		return (SKIP_BODY);
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public long getLongTime() {
		return longTime;
	}

	public void setLongTime(long longTime) {
		this.longTime = longTime;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

}
